#lang r5rs
;;
(define (make-acc base)
  (define basis base)
  (lambda(x)
    (begin
      (set! basis (+ basis x))
      basis)))
(define A (make-acc 5))
(display (A 10))
(display (A 10))

(define (make-monitor f)
  (define times 0)
  (lambda(x)
    (if(eq? x 'how-many-calls)
       times
       (begin
         (set! times (+ times 1))
         (f x)))))
(define s (make-monitor sqrt))
(display (s 100))
(display (s 'how-many-calls))
;3.3 3.4 is so boring
;(define accq (let ((x 1)) (lambda () (set! x (+ 1 x)) x)))
;(define g (let ((a 1) (b 2)) + a b))
;(define h (let ((a 1) (b 2)) (+ a b)))
;(display (lambda () (+ 1 1)))
;(display ((lambda () (+ 1 1))))
;(display  (define (add a b) (add a b)))
(define X (lambda () (+ 1 1)))